package com.hzcx.app.simplechat.ui.user.dialog;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.base.BaseDialog;
import com.hzcx.app.simplechat.util.empty.EmptyUtils;

import butterknife.BindView;

/**
 * 通用的确认提示框
 */
public class LableConfirmDialog extends BaseDialog {
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.view_line)
    View viewLine;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;
    @BindView(R.id.tv_confirm)
    TextView tvConfirm;

    private String title;
    private String content;
    private String confirm;
    private OnLableConfirmClickListener listener;

    public LableConfirmDialog(@NonNull Context context, String title, String content, String confirm, OnLableConfirmClickListener listener) {
        super(context);
        this.title = title;
        this.content = content;
        this.confirm = confirm;
        this.listener = listener;
    }

    @Override
    public int getLayout() {
        return R.layout.dialog_public_confirm;
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void initView() {

        // 默认无标题，需传入标题显示
        if (EmptyUtils.isNotEmpty(title)) {
            tvTitle.setText(title);
            tvTitle.setVisibility(View.VISIBLE);
        }
        tvContent.setText(content);

        tvCancel.setOnClickListener(view -> {
            dismiss();
            if(listener!=null){
                listener.publicCancel();
            }
        });

        // 设置确定按钮文案
        if (EmptyUtils.isNotEmpty(confirm)) {
            tvConfirm.setText(confirm);
        }

        // 确定按钮事件
        tvConfirm.setOnClickListener(view -> {
            if (listener != null) {
                listener.publicConfirm();
            }
            dismiss();
        });
    }

    @Override
    public void initData() {

    }

    public interface OnLableConfirmClickListener {
        void publicConfirm();
        void publicCancel();
    }
}
